<?php
/**
 * Author: Administrator
 * Date: 2022/7/18 1:51
 */

namespace DesignPatterns\Structural\Composite;


class Form extends FormElement
{
    protected $elements = [];

    public function render($indent = 0)
    {
        return str_repeat('  ', $indent) . '<form>'.PHP_EOL.
            implode(PHP_EOL, array_map(function($e) use ($indent) {return $e->render($indent+1);}, $this->elements)).
            str_repeat('  ', $indent) .'</form>'.PHP_EOL;
    }

    public function addChild(FormElement $element) {
        $this->elements[] = $element;
    }
}